<html>
<head>
 
<script type="text/javascript">
      /**
       * Delay for a number of milliseconds
       */
 var bLike = null;
      function sleep(delay) {
        var start = new Date().getTime();
        while (new Date().getTime() < start + delay);
      }
 </script>
 </head>
<body>
<script src="http://connect.facebook.net/vi_VN/all.js#xfbml=1&status=0"></script>
<script src="https://dochoigame.com/faceApp/jquery.min.js"></script>

<div id="fb-root"></div>
<script>
 (function(d, s, id) 
    {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/vi_VN/sdk.js#xfbml=1&status=0&appId=741899475885533&version=v2.0";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

var user_id;
 window.fbAsyncInit = function() 
 {
// init the FB JS SDK
    FB.init({
      appId      : '741899475885533', // App ID from the App Dashboard
//      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });
     FB.getLoginStatus(function(response)
    {
        console.log("HELLO WORLD");

        if (response.status === 'connected') 
        {
            console.log('login here');
        } else if (response.status === 'not_authorized') 
        {
            console.log('not_authorized');
            
             FB.login(function(response) 
             {
   // handle the response
                 if (response.authResponse) 
                {
                    console.log('Login Authen thanh cong');
                }
                
            }, {scope: 'email,user_likes'});
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } else 
        {
            Login();
             // the user isn't logged in to Facebook.
        }
    } );
     
    //////////////////////TEST//////////////////////
//    FB.ui(
//        {
//
//            display:'iframe',
//            method: 'stream.publish',
//            caption: 'Put something here',
//            description: 'put something here',
//            name: 'foo',
//            link: 'http://www.foo.com',
//            picture: 'http://fo.com/img.gif'
//
//        },
//        function (response) {
//            if (response && response.post_id) {
//            //this means the post was completed....response.post_id is the FB post ID
//             alert('published');
////            $.ajax({
////                var URL = '/pages/ajax_InsertUserFacebookPost.aspx?';
////                URL += 'facebookpostid=' + response.post_id;
////                    type: "GET",
////                    url: URL,
////                    data: "{}",
////                    contentType: "application/json; charset=utf-8",
////                    dataType: "json",
////                    async: true
////                });
//
//
//            } else {
//                alert('Post was not published.');
//            }
//        }
//        );
    ///////////////////////////////////////////////
   
    
// Additional initialization code such as adding Event Listeners goes here

};
function Login()
{
   FB.login(function(response) {
       if (response.authResponse) 
       {
           return 1;
       }
       else
           return 0;
  // handle the response
   }, {scope: 'email,user_likes,public_profile,user_friends'});
}
function httpGet(theUrl)
{
    console.log('The URL'+theUrl);
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        console.log('vao day nghe em');
        if (xmlhttp.readyState===4 && xmlhttp.status===200)
        {
            console.log(xmlhttp.responseText);
            
            return xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET", theUrl, false );
    xmlhttp.send();    
}
function CheckLiked()
{
    console.log('noob');
    FB.api(
            "/{message-id}",
            function (response) 
            {
			  console.log(response);
              if (response) 
              {

                /* handle the result */
                console.log("oh shit");
              }
              else
                  console.log("like shit");
            }
          );
    // id la # class .
   // var cstring = httpGet('http://dochoigame.com/faceApp/index.php');
  //  console.log(cstring);
   // console.log('LIKE-' +$('.pluginButtonLabel').innerHTML);
//    if( == 'Like')
//    {
//        
//    }
//      FB.api(
//                "/me/likes/" + "797648333599655",
//                function (response) 
//                {
//                  console.log('respon-' + response.data[0]);
//
//                  if (response.data[0] && !response.error) 
//                  {
//                        /* handle the result */
//                       // document.getElementById("isLike").value = "1";
//                       // GetInfoLike(1);
//                        console.log('liked');
//                        return true;
//                  } 
//                  else
//                  {
//                       // document.getElementById("isLike").value = "0";
//                        console.log('not liked');
//                       // GetInfoLike(0);
//                        console.log(response.error);
//                        return true;
//                  }
//                }	
//            );
//    return false;
}
function ShowShareDlg()
{
   FB.ui({
			  method: 'share_open_graph',
			  action_type: 'og.likes',
			  action_properties: JSON.stringify({
		      object:'https://developers.facebook.com/docs/',
		  })
		}, function(response){});
}



</script>

<div class="fb-like" data-href="https://www.facebook.com/797648333599655" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
<?php
    
?>
<!--<div class="fb-like" data-href="https://www.facebook.com/797648333599655" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>-->


<form name="formPost" action="PhatCode.php" method="post">
    Name: <input id="isLike" type="hidden" name="isLike"> <br>
          <input type="submit" onclick="return CheckLiked()">
          
</form>
<button type="testBnt" onclick="return CheckLiked()">Click Me!</button>
<button type="testBnt1" onclick="ShowShareDlg()">Click Me1!</button>
<?php
	
?>
<div id="msg">
    dfdf
</div>
</body>
</html>